import datetime
import random

from faker import Faker
from app import db
from models.user import UserUser
from models.game import GameGame
from models.payment import PaymentPay
f = Faker(locale='zh_CN')
tag_list = ['fps','MOBA','卡牌','休闲','模拟','益智','回合','求生',
            '多人','单机','冒险','动作','养成','恋爱','角色扮演',
            '体育','赛车','棋牌','恐怖']
game_names = ['lol','dota2','cf','dnf','拳皇',
              '炉石传说','生化危机','求生之路','喋血复仇','剑与远征',
              '梦幻西游','三国杀','传奇','卡丁车','暴力摩托',
              '2408','nba2k15','fifa','欢乐斗地主','中国象棋',
              '中国麻将','绝地求生','纸人','港诡实录','九州仙剑传']
def faker_user(count=10000):
    names = []
    for i in range(count):
        name = f.name()
        tag = list(set(random.choices(population=tag_list,k=3)))
        while name in names:
            name = f.name()
        obj = UserUser(name=name,like_game_tag=tag)
        db.session.add(obj)
        names.append(f.name())
    db.session.commit()

def faker_game():
    for i in range(25):
        category_list = list(set(random.choices(population=tag_list,k=4)))
        game = GameGame(name=game_names[i],category_list=category_list,priority=random.randint(1,100))
        db.session.add(game)
    db.session.commit()

def faker_payment():
    l = random.randint(200,600)
    for i in range(l):
        user_id = random.randint(1,10000)
        game_id = random.randint(1002,1026)
        pay_type = random.randint(1,3)
        order_date = f.date_between_dates(datetime.date(2021,1,1),datetime.date.today())
        order_time =order_date.strftime('%Y-%m-%d ')+f.time()
        order_time = datetime.datetime.strptime(order_time, '%Y-%m-%d %H:%M:%S')
        user_pay_money = random.randint(1,1000)
        payment = PaymentPay(user_id=user_id,game_id=game_id,pay_type=pay_type,user_pay_money=user_pay_money,
                             order_date=order_date,order_time=order_time)
        db.session.add(payment)
    db.session.commit()


if __name__ == '__main__':
    faker_payment()
